package net.istore.market.dao.user;

import net.istore.market.dao.AbstractDAO;
import net.istore.market.domain.User;
import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

/**
 * Created by Ivan_Zhuravel on 1/13/15.
 */
@Repository
public class UserDaoImpl extends AbstractDAO implements UserDao {

    private static final String USERNAME_FIELD = "username";

    @Override
    public User findByUserName(String username) {
        Criteria criteria = sessionFactory.getCurrentSession().createCriteria(User.class);
        criteria.add(Restrictions.eq(USERNAME_FIELD, username));

        return (User) criteria.uniqueResult();
    }

    @Override
    public User addUser(User user) {
        return persistEntity(user);
    }
}
